/// @author Alberto Franco
/// @date   23-05-2011
/// @file   channel_passing.go
/// @brief  Contains an experiment for pi-calculus capabilites of Go.
///         In this program channel passing is implemented
package picalculus

import (
    "fmt"
)

/// Main program function
func ChannelPassing_Main() {
    var chanOfChan chan chan int
    var myChan chan int
    
    chanOfChan = make(chan chan int)
    go supportGoroutine(&chanOfChan)
    
    for i := 0; i < 10; i++ {
        myChan = make(chan int)
        fmt.Println("Sending channel")
        chanOfChan <- myChan
        integer := <- myChan
        fmt.Println("Received ", integer)
    }
}

/// Receive a commuication channel and send data over the channel received.
/// @param channel The channel of channel
func supportGoroutine(channel *chan chan int) {
    var supportChan chan int
    for i := 0; i < 10; i++ {
        fmt.Println("Acquire channel")
        supportChan = <- (*channel)
        fmt.Println("Sending data over channel")
        supportChan <- i
    }
}
